/*
 * Copyright 2009 Eat Local Food, LLC
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.elf.gwt.common.client.access;

import java.util.Date;

import com.google.gwt.http.client.URL;

/**
 * Class that represents a request parameter on a url.
 */

public class RequestParameter
{
	private String key;
	private String value;
	
	public RequestParameter()
	{
		this.key = null;
		this.value = null;
	}
	
	public RequestParameter(String key, String value)
	{
		this.key = key;
		this.value = value;
	}
	
	public RequestParameter(String key, int value)
	{
		this.key = key;
		this.value = String.valueOf(value);
	}
	
	public RequestParameter(String key, double value)
	{
		this.key = key;
		this.value = String.valueOf(value);
	}
	
	public RequestParameter(String key, boolean value)
	{
		this.key = key;
		this.value = "0";
		if (value) this.value = "1";
	}
	
	public RequestParameter(String key, Date value)
	{
		this.key = key;
		this.value = "0";
		if (value != null) this.value = String.valueOf(value.getTime());
	}
	
	public String getKey() {
		return URL.encode(key);
	}
	
	public void setKey(String key) {
		this.key = key;
	}
	
	public String getValue() {
		if (value == null) return value;
		return URL.encodeQueryString(value);
	}
	
	public String getRawValue() {
		if (value == null) return value;
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
}
